package com.zzyl.nursing.controller.member;

import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.common.core.domain.R;
import com.zzyl.common.utils.UserThreadLocal;
import com.zzyl.nursing.dto.ElderHealthDto;
import com.zzyl.nursing.dto.MemberElderDto;
import com.zzyl.nursing.dto.UserLoginRequestDto;
import com.zzyl.nursing.service.IFamilyMemberElderService;
import com.zzyl.nursing.service.IFamilyMemberService;
import com.zzyl.nursing.vo.DeviceDataDailyVo;
import com.zzyl.nursing.vo.FamilyMemberElderVo;
import com.zzyl.nursing.vo.LoginVo;
import com.zzyl.nursing.vo.MemberElderVo;
import com.zzyl.nursing.vo.health.ElderHealthVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

/**
 * 老人家属Controller
 */
@RestController
@RequestMapping("/member/user")
@Api(tags = "老人家属的接口")
public class FamilyMemberController extends BaseController
{
    @Autowired
    private IFamilyMemberService familyMemberService;
    @Autowired
    private IFamilyMemberElderService familyMemberElderService;


    @PostMapping("/login")
    @ApiOperation("小程序登录")
    public AjaxResult login(@RequestBody UserLoginRequestDto dto){
        LoginVo loginVo = familyMemberService.login(dto);
        return success(loginVo);
    }

    /**
     * 绑定家属
     */
    @PostMapping("/add")
    @ApiOperation("绑定家属")
    public AjaxResult add(@RequestBody MemberElderDto memberElderDto){
        familyMemberElderService.add(memberElderDto);
        return success();
    }

    /**
     * 查询家人列表
     */
    @GetMapping("/my")
    @ApiOperation("查询家人列表")
    public R<List<FamilyMemberElderVo>> my() {
        List<FamilyMemberElderVo> memberElders = familyMemberElderService.my();
        return R.ok(memberElders);
    }

    /**
     * 分页查询老人关联信息
     */
    @GetMapping("/list-by-page")
    @ApiOperation("分页查询老人关联信息")
    public R<List<MemberElderVo>> listByPage(Integer pageNum, Integer pageSize) {
        startPage();
        Long userId1 = UserThreadLocal.getUserId();
        List<MemberElderVo> memberElders = familyMemberElderService.listByPage(userId1);
        return R.ok(memberElders);
    }

    /**
     * 查询健康数据
     */
    @GetMapping("/queryServiceProperties/{iotId}")
    @ApiOperation("查询健康数据")
    public AjaxResult queryDevicePropertyStatus(@PathVariable String iotId){
        AjaxResult ajaxResult = familyMemberElderService.queryDevicePropertyStatus(iotId);
        return ajaxResult;
    }

    /**
     * 按天统计查询指标数据
     */
@GetMapping("/queryDeviceDataListByDay")
@ApiOperation("按天统计查询指标数据")
public R<List<DeviceDataDailyVo>> queryDeviceDataListByDay(@RequestParam String iotId,
                                                           @RequestParam Long startTime,
                                                           @RequestParam Long endTime,
                                                           @RequestParam String functionId){
    List<DeviceDataDailyVo> deviceDataDailyList = familyMemberElderService.queryDeviceDataListByDay(iotId, startTime, endTime, functionId);
    return R.ok(deviceDataDailyList);
}

    /**
     * 按周统计查询指标数据
     */
    @GetMapping("/queryDeviceDataListByWeek")
    @ApiOperation("按天统计查询指标数据")
    public R<List<Map<String,Object>>> queryDeviceDataListByWeek(@RequestParam String iotId,
                                                               @RequestParam Long startTime,
                                                               @RequestParam Long endTime,
                                                               @RequestParam String functionId){
        List<Map<String,Object>> deviceDataDailyList = familyMemberElderService.queryDeviceDataListByWeek(iotId, startTime, endTime, functionId);
        return R.ok(deviceDataDailyList);
    }

}
